package datastructures;

import java.util.*;

public class MultiHashMap<K,V> extends HashMap<K, HashMap<K,V>>{

	boolean unordered = false;
	public MultiHashMap()
	{
		super();
	}
	
	/**
	 * 
	 * @param bidirectional if true, not bidirectional map if false.
	 */
	public MultiHashMap(boolean unordered)
	{
		super();
		this.unordered = unordered;
	}
	
	
	public V put(K k1, K k2, V value)
	{

		if ( unordered && (!this.containsKey(k1) || !this.containsKey(k2)) )
		{
			put(k1, new HashMap<K,V>());
			put(k2, new HashMap<K,V>());
			this.get(k2).put(k1, value);
			return this.get(k1).put(k2, value);
		}
		else
		{
			if (!this.containsKey(k1))
			{
				put(k1, new HashMap<K,V>());
			}
			return this.get(k1).put(k2, value);
		}
	}
	
	public V get(K k1, K k2)
	{
		if (!this.containsKey(k1)) return null;
		return this.get(k1).get(k2);
	}
	
	public boolean containsKey(K k1, K k2)
	{
		return containsKey(k1) && get(k1).containsKey(k2);
	}
}
